<?php
header( "Content-type: text/xml" );
echo '<?xml version="1.0" encoding="utf-8" ?>';

$this_file = str_replace( '\\', '/', __FILE__ );
$this_file = explode( 'wp-content', $this_file );
$this_file = $this_file[ 0 ];
require( $this_file . 'wp-blog-header.php' );

// get options
$aOptions = SofaSuppaStore::initOptions( false );
$pm_pieces = $aOptions[ 'pm_pieces' ];
$pm_time = $aOptions[ 'pm_time' ];
$pm_transition = $aOptions[ 'pm_transition' ];
$pm_delay = $aOptions[ 'pm_delay' ];
$pm_depthoffset = $aOptions[ 'pm_depthoffset' ];
$pm_cubedistance = $aOptions[ 'pm_cubedistance' ];
$pm_loadercolor = $aOptions[ 'pm_loadercolor' ];
$pm_innersidecolor = $aOptions[ 'pm_innersidecolor' ];
$pm_sideshadowalpha = $aOptions[ 'pm_sideshadowalpha' ];
$pm_dropshadowalpha = $aOptions[ 'pm_dropshadowalpha' ];
$pm_dropshadowdistance = $aOptions[ 'pm_dropshadowdistance' ];
$pm_dropshadowscale = $aOptions[ 'pm_dropshadowscale' ];
$pm_dropshadowblurx = $aOptions[ 'pm_dropshadowblurx' ];
$pm_dropshadowblury = $aOptions[ 'pm_dropshadowblury' ];
$pm_menudistancex = $aOptions[ 'pm_menudistancex' ];
$pm_menudistancey = $aOptions[ 'pm_menudistancey' ];
$pm_menucolor1 = $aOptions[ 'pm_menucolor1' ];
$pm_menucolor2 = $aOptions[ 'pm_menucolor2' ];
$pm_menucolor3 = $aOptions[ 'pm_menucolor3' ];
$pm_controlsize = $aOptions[ 'pm_controlsize' ];
$pm_controldistance = $aOptions[ 'pm_controldistance' ];
$pm_controlcolor1 = $aOptions[ 'pm_controlcolor1' ];
$pm_controlcolor2 = $aOptions[ 'pm_controlcolor2' ];
$pm_controlalpha = $aOptions[ 'pm_controlalpha' ];
$pm_controlalphaover = $aOptions[ 'pm_controlalphaover' ];
$pm_controlsx = $aOptions[ 'pm_controlsx' ];
$pm_controlsy = $aOptions[ 'pm_controlsy' ];
$pm_controlsalign = $aOptions[ 'pm_controlsalign' ];
$pm_tooltipheight = $aOptions[ 'pm_tooltipheight' ];
$pm_tooltipcolor = $aOptions[ 'pm_tooltipcolor' ];
$pm_tooltiptexty = $aOptions[ 'pm_tooltiptexty' ];
$pm_tooltiptextstyle = $aOptions[ 'pm_tooltiptextstyle' ];
$pm_tooltiptextcolor = $aOptions[ 'pm_tooltiptextcolor' ];
$pm_tooltipmarginleft = $aOptions[ 'pm_tooltipmarginleft' ];
$pm_tooltipmarginright = $aOptions[ 'pm_tooltipmarginright' ];
$pm_tooltiptextsharpness = $aOptions[ 'pm_tooltiptextsharpness' ];
$pm_tooltiptextthickness = $aOptions[ 'pm_tooltiptextthickness' ];
$pm_infowidth = $aOptions[ 'pm_infowidth' ];
$pm_infobackground = $aOptions[ 'pm_infobackground' ];
$pm_infobackgroundalpha = $aOptions[ 'pm_infobackgroundalpha' ];
$pm_infomargin = $aOptions[ 'pm_infomargin' ];
$pm_infosharpness = $aOptions[ 'pm_infosharpness' ];
$pm_infothickness = $aOptions[ 'pm_infothickness' ];
$pm_autoplay = $aOptions[ 'pm_autoplay' ];
$pm_fieldofview = $aOptions[ 'pm_fieldofview' ];
?>

<?php
// query nivo-slides custom post type
$slide_args = array(
	'post_type' => array( 'nivo-slide' ),
	'posts_per_page' => -1,
	'post_status' => 'published',
	'nopaging' => 'true',
	'orderby' => 'title',
	'order' => 'ASC'
);
// build WP query
$slide_query = new WP_Query( $slide_args );
?>

<?php if( $slide_query->have_posts() ) :  ?>

<Piecemaker>
  <Contents>
  
<?php while ( $slide_query->have_posts() ) : $slide_query->the_post(); ?>  

	<?php
    // extract image
    if( has_post_thumbnail( $post->ID ) ) {
        $att_args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => 'published', 'post_parent' => $post->ID );
        $all_attachments = get_posts( $att_args );
        $slide_link = get_post_meta( $all_attachments[ 0 ]->ID, '_url', true );
        $default_attr = array( 'class' => "alignleft" );
        $full_slide_path = get_the_post_thumbnail( get_the_ID(), 'full', $default_attr );
        $slide_img_path = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
		$caption_text = get_post_meta( $post->ID, 'caption_text', true );
    }
    ?>
  
    <Image Source="<?php echo $slide_img_path[ 0 ]; ?>" Title="<?php echo $caption_text; ?>">
      <Hyperlink URL="<?php echo $slide_link; ?>" Target="_self" />
    </Image>
    
<?php endwhile; else : ?>

    <Image Source="<?php echo get_template_directory_uri() . 'images/noslide.jpg'; ?>" Title="No slide found!"></Image>
    
<?php endif; ?>
    
  </Contents>
  <Settings ImageWidth="930" ImageHeight="350" LoaderColor="<?php echo $pm_loadercolor; ?>" InnerSideColor="<?php echo $pm_innersidecolor; ?>" SideShadowAlpha="<?php echo $pm_sideshadowalpha; ?>" DropShadowAlpha="<?php echo $pm_dropshadowalpha; ?>" DropShadowDistance="<?php echo $pm_dropshadowdistance; ?>" DropShadowScale="<?php echo $pm_dropshadowscale; ?>" DropShadowBlurX="<?php echo $pm_dropshadowblurx; ?>" DropShadowBlurY="<?php echo $pm_dropshadowblury; ?>" MenuDistanceX="<?php echo $pm_menudistancex; ?>" MenuDistanceY="<?php echo $pm_menudistancey; ?>" MenuColor1="<?php echo $pm_menucolor1; ?>" MenuColor2="<?php echo $pm_menucolor2; ?>" MenuColor3="<?php echo $pm_menucolor3; ?>" ControlSize="<?php echo $pm_controlsize; ?>" ControlDistance="<?php echo $pm_controldistance; ?>" ControlColor1="<?php echo $pm_controlcolor1; ?>" ControlColor2="<?php echo $pm_controlcolor2; ?>" ControlAlpha="<?php echo $pm_controlalpha; ?>" ControlAlphaOver="<?php echo $pm_controlalphaover; ?>" ControlsX="<?php echo $pm_controlsx; ?>" ControlsY="<?php echo $pm_controlsy; ?>" ControlsAlign="<?php echo $pm_controlsalign; ?>" TooltipHeight="<?php echo $pm_tooltipheight; ?>" TooltipColor="<?php echo $pm_tooltipcolor; ?>" TooltipTextY="<?php echo $pm_tooltiptexty; ?>" TooltipTextStyle="<?php echo $pm_tooltiptextstyle; ?>" TooltipTextColor="<?php echo $pm_tooltiptextcolor; ?>" TooltipMarginLeft="<?php echo $pm_tooltipmarginleft; ?>" TooltipMarginRight="<?php echo $pm_tooltipmarginright; ?>" TooltipTextSharpness="<?php echo $pm_tooltiptextsharpness; ?>" TooltipTextThickness="<?php echo $pm_tooltiptextthickness; ?>" InfoWidth="<?php echo $pm_infowidth; ?>" InfoBackground="<?php echo $pm_infobackground; ?>" InfoBackgroundAlpha="<?php echo $pm_infobackgroundalpha; ?>" InfoMargin="<?php echo $pm_infomargin; ?>" InfoSharpness="<?php echo $pm_infosharpness; ?>" InfoThickness="<?php echo $pm_infothickness; ?>" Autoplay="<?php echo $pm_autoplay; ?>" FieldOfView="<?php echo $pm_fieldofview; ?>"></Settings>
  <Transitions>
    <Transition Pieces="<?php echo $pm_pieces; ?>" Time="<?php echo $pm_time; ?>" Transition="<?php echo $pm_transition; ?>" Delay="<?php echo $pm_delay; ?>" DepthOffset="<?php echo $pm_depthoffset; ?>" CubeDistance="<?php echo $pm_cubedistance; ?>"></Transition>
  </Transitions>
</Piecemaker>